home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cocktail
/
cg.lha
/
cg
/
test-m
/
Main.mi
< prev
next >
Wrap
Text File
|
1992-11-24
|
3KB
|
122 lines
MODULE Main;
FROM System IMPORT System;
FROM Checks IMPORT ErrorCheck;
FROM Strings IMPORT tString, ArrayToString;
FROM Idents IMPORT MakeIdent;
FROM IO IMPORT tFile, ReadOpen, ReadClose, WriteOpen, WriteClose, CloseIO;
FROM StdIO IMPORT WriteS, WriteI, WriteC, WriteNl;
FROM Tree IMPORT tTree, nNode1, nNode2, BeginTree, CloseTree, QueryTree,
WriteTree, ReadTree, PutTree, GetTree, CopyTree, TraverseTreeTD,
TraverseTreeBU, CheckTree, ReleaseTree, ReleaseTreeModule;
VAR n, n1, n2, n3, n4, n5, Root1, Root2, Root3: tTree;
f: tFile;
i: INTEGER;
s: tString;
PROCEDURE PrintMark (t: tTree);
BEGIN
WriteI (t^.Node.Mark, 0);
WriteC (' ');
END PrintMark;
BEGIN
BeginTree;
n1 := nNode2 ();
n2 := nNode2 ();
n3 := nNode1 ();
n4 := nNode1 ();
n5 := nNode1 ();
n1^.Node.Mark := 1;
n2^.Node.Mark := 2;
n3^.Node.Mark := 3;
n4^.Node.Mark := 4;
n5^.Node.Mark := 5;
ArrayToString ("1", s); n1^.Node.Ident := MakeIdent (s);
ArrayToString ("2", s); n2^.Node.Ident := MakeIdent (s);
ArrayToString ("3", s); n3^.Node.Ident := MakeIdent (s);
ArrayToString ("4", s); n4^.Node.Ident := MakeIdent (s);
ArrayToString ("5", s); n5^.Node.Ident := MakeIdent (s);
n1^.Node.Hex := 1;
n2^.Node.Hex := 2;
n3^.Node.Hex := 3;
n4^.Node.Hex := 4;
n5^.Node.Hex := 5;
n := n1;
n1^.Node2.Child1 := n2;
n1^.Node2.Child2 := n2;
n2^.Node2.Child1 := n3;
n2^.Node2.Child2 := n5;
n3^.Node1.Child1 := n4;
n4^.Node1.Child1 := n3;
n5^.Node1.Child1 := n5;
f := WriteOpen ("a");
ErrorCheck ("WriteOpen (a)", f);
WriteS ("WriteOpen (a)"); WriteNl;
WriteTree (f, n);
WriteClose (f);
f := ReadOpen ("a");
ErrorCheck ("ReadOpen (a)", f);
WriteS ("ReadOpen (a)"); WriteNl;
Root1 := ReadTree (f);
ReadClose (f);
f := WriteOpen ("b");
ErrorCheck ("WriteOpen (b)", f);
WriteS ("WriteOpen (b)"); WriteNl;
PutTree (f, Root1);
WriteClose (f);
f := ReadOpen ("b");
ErrorCheck ("ReadOpen (b)", f);
WriteS ("ReadOpen (b)"); WriteNl;
Root2 := GetTree (f);
ReadClose (f);
f := WriteOpen ("aa");
ErrorCheck ("WriteOpen (aa)", f);
WriteS ("WriteOpen (aa)"); WriteNl;
WriteTree (f, Root2);
WriteClose (f);
f := WriteOpen ("bb");
ErrorCheck ("WriteOpen (bb)", f);
WriteS ("WriteOpen (bb)"); WriteNl;
PutTree (f, Root2);
WriteClose (f);
Root3 := CopyTree (Root2);
f := WriteOpen ("aaa");
ErrorCheck ("WriteOpen (aaa)", f);
WriteS ("WriteOpen (aaa)"); WriteNl;
WriteTree (f, Root3);
WriteClose (f);
i := System ("set -x; cmp a aa; cmp b bb; cmp a aaa");
ErrorCheck ("System", i);
WriteS ("should print:"); WriteNl;
WriteS ("1 2 3 4 5 4 3 5 2 1 "); WriteNl;
TraverseTreeTD (Root2, PrintMark);
TraverseTreeBU (Root2, PrintMark);
WriteNl ;
IF CheckTree (Root3) THEN END;
WriteS ("should print:"); WriteNl;
WriteS ("4 3 5 2 1 "); WriteNl;
ReleaseTree (Root3);
WriteNl ;
ReleaseTreeModule ;
CloseTree ;
CloseIO;
END Main.